package com.repast.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.repast.common.Const;
import com.repast.common.ServerResponse;
import com.repast.dao.BackgroundImgMapper;
import com.repast.dao.RestaurantInfoMapper;
import com.repast.pojo.BackgroundImg;
import com.repast.pojo.RestaurantInfo;
import com.repast.service.IBackgroundImgService;
import com.repast.vo.BgImgAndRestaurantInfo;

@Service
public class BackgroundImgServiceImpl implements IBackgroundImgService {

	@Autowired
	private BackgroundImgMapper bgMapper;
	@Autowired
	private RestaurantInfoMapper rsMapper;

	public ServerResponse showBg() {
		List<BackgroundImg> list = bgMapper.selectBgList();
		if(list.size()==0){
			return ServerResponse.createBySuccessMessage("没有默认展示的图片");
		}
		String url= list.get(0).getBgUrl();
		//RestaurantInfo rsInfo = rsMapper.selectDefaultRestaurantInfo(Const.DEFAULT_RS_INFO);
		List<RestaurantInfo> rsList = rsMapper.selectRestaurant();
		BgImgAndRestaurantInfo info = new BgImgAndRestaurantInfo();
		info.setBg_url(url);
		if (rsList.size() != 0) {
			info.setRestaurant_info_name(rsList.get(0).getRestaurantInfoName());
			info.setRestaurant_info_hours(rsList.get(0).getRestaurantInfoHours());
			info.setRestaurant_info_location(rsList.get(0).getRestaurantInfoLocation());
			info.setRestaurant_info_phone(rsList.get(0).getRestaurantInfoPhone());
		}
		if (rsList.size() == 0) {
			return ServerResponse.createBySuccessMessage("没有默认展示的餐厅信息");
		}
		return ServerResponse.createBySuccess(info);
	}
}
